package com.example.intenttrial;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ProgressActivity extends Activity {

	TextProgressBar tpb;
	Button btnWifi;
	WifiManager wifiManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.ll_progress);
		tpb = (TextProgressBar) findViewById(R.id.progressBarWithText);
		tpb.setProgress(0);
		tpb.setTextSize(18);

		wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
		
		Button btn = (Button) findViewById(R.id.btn);
		btnWifi = (Button) findViewById(R.id.btnwifi);
		
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				int currProgress = tpb.getProgress();
				tpb.setProgress(currProgress + 1);
			}
		});

		btnWifi.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				
				turnWifi(!wifiManager.isWifiEnabled());
				
			}
		});
	}

	private void turnWifi(boolean enabled) {
		try {
			System.out.println(wifiManager.setWifiEnabled(enabled));
		} catch (Exception ignored) {
			ignored.printStackTrace();
		}
	}

}
